package com.xbongbong.paas.help.symbol;

import com.ql.util.express.OperatorOfNumber;
import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.toolbox.exception.XbbException;

import java.util.Objects;

/**
 * @author 吴峰
 * @date 2021/01/07 14:33
 */
public class NumSymbolHandle extends TextSymbolHandle {

    @Override
    public boolean equals(Object target, PaasFormDataEntity source, FieldAttrEntity fieldAttrEntity) throws XbbException {
        if (Objects.isNull(source.getData().get(fieldAttrEntity.getAttr()))) {
            return false;
        }
        Number a = (Number) source.getData().get(fieldAttrEntity.getAttr());
        Number b = (Number) target;
        int result = OperatorOfNumber.compareNumber(a, b);
        return result == 0;
    }

    @Override
    public boolean noEquals(Object target, PaasFormDataEntity source, FieldAttrEntity fieldAttrEntity) throws XbbException {
        if (Objects.isNull(source.getData().get(fieldAttrEntity.getAttr()))) {
            return true;
        }
        Number a = (Number) source.getData().get(fieldAttrEntity.getAttr());
        Number b = (Number) target;
        int result = OperatorOfNumber.compareNumber(a, b);
        return result != 0;
    }
}
